package com.example.apidemo2;

import java.io.File;
import java.io.IOException;


import android.media.MediaPlayer;

public class AudioChannelTest {
	
	private static String mstrFilePath = null;
	private static MediaPlayer mMediaPlayer = null;
	
	private static boolean mbAudioChannelTest = false;
	
	public static void AudioLeftRightChannelTest()
	{
		if(mbAudioChannelTest)
			return;
	
		mbAudioChannelTest = true;
		
		SysActivity.SendPromptMsg("Start sound test... \r\n");
		
		mMediaPlayer  =   new MediaPlayer();
		
		mstrFilePath = "/sdcard/" + "TestAudio.mp3";
		
		File file = new File(mstrFilePath);
		
		if(!file.exists())
		{
			SysActivity.SendPromptMsg("Audio file is not exist\r\n");
			mbAudioChannelTest = false;
			return;
		}
		
        try {
        	mMediaPlayer.setDataSource(mstrFilePath);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        try {
        	mMediaPlayer.prepare();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        mMediaPlayer.start();
	}
	
	public static void EndAudioLeftRightChannelTest()
	{
		mbAudioChannelTest = false;
		
		if(null != mMediaPlayer)
			mMediaPlayer.stop();
	}

}
